<?php

namespace Trawind\Extension\Transformers\Custom;

use Trawind\Basics\TrawindTransformer;
use Trawind\Remotes\Repositories\Extension\Custom\FormRepositoryEloquent;

class CustomFormTransformer extends TrawindTransformer
{

    use CustomTransformer;

    protected function getDetails()
    {
        $formId = request()->input('form_id', 0);
        $details = app(FormRepositoryEloquent::class)
            ->details($this->businessTypeId, $formId);

        [$remoteBusinessType, $localBusinessType] = $this->collectWithParam($details);
        return [
            'fields' => array_column($details['fields'], 'field'),
            'localBusinessType' => $localBusinessType,
            'remoteBusinessType' => $remoteBusinessType,
        ];
    }


    public function diyFillTransformData(array $data)
    {
        $_data = $this->buildRelationFieldToData([$data['data']]);
        $data['data'] = array_shift($_data);
        return $data;
    }

}